/**
 * 
 */
package org.xlab.baseframework.listener;

import java.util.Locale;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationListener;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;
import org.xlab.baseframework.event.SystemParameterRemovedEvent;
import org.xlab.baseframework.system.SystemRuntimeEnvironment;

/**
 * 系统参数更变监听器,该监听器将更新系统缓存
 * 
 * @author MaKuBEX
 * 
 */
@Component
public class SystemParameterRemovedListener implements
		ApplicationListener<SystemParameterRemovedEvent> {

	private static final Logger log = Logger
			.getLogger(SystemParameterRemovedListener.class);
	@Autowired(required = true)
	@Qualifier("bpf_systemParameterServiceMessageSource")
	private MessageSource messageSource;

	public MessageSource getMessageSource() {
		return messageSource;
	}

	/**
	 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
	 */
	public void onApplicationEvent(SystemParameterRemovedEvent event) {
		String message = null;
		this.messageSource.getMessage("info.system.event.syspmremoved",
				new Object[] { event.getCode() }, Locale.getDefault());
		log.debug(message);
		SystemRuntimeEnvironment.removeParameter(event.getCode());
	}

	public void setMessageSource(MessageSource messageSource) {
		this.messageSource = messageSource;
	}

}
